<?php

class MarqueController extends Zend_Controller_Action
{



    public function init()
    {
        /* Initialize action controller here */
    	$layout=$this->_helper->layout();
    	$layout->setLayout('adminlayout');
    }

    public function indexAction()
    {
        $marques=new Application_Model_DbTable_Marques();
    	$this->view->marques =$marques->fetchAll();
    }

    public function addAction()
    {
    $form = new Application_Form_Marque();
    $form->envoyer->setLabel('Ajouter');
    $this->view->form = $form;

    if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) {
            $nom_marque = $form->getValue('nom_marque');
            
            $marques = new Application_Model_DbTable_marques();
            $marques->addmarque($nom_marque);

            $this->_helper->redirector('index');
        } else {
            $form->populate($formData);
        }
    }
    }

    public function updateAction()
    {
    $form = new Application_Form_Marque();
    $form->envoyer->setLabel('Sauvegarder');
    $this->view->form = $form;

    if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) {
            $id = $form->getValue('id');
            $nom_marque = $form->getValue('nom_marque');
            $marques = new Application_Model_DbTable_Marques();
            $marques->updatemarque($id, $nom_marque);

            $this->_helper->redirector('index');
        } else {
            $form->populate($formData);
        }
    } else {
        $id = $this->_getParam('id', 0);
        if ($id > 0) {
            $marques = new Application_Model_DbTable_Marques();
            $form->populate($marques->getmarque($id));
        }
    }
    }

    public function deleteAction()
    {
        // action body
    }


}



